// system.h 
//	All global variables used in Nachos are defined here.
//
// Copyright (c) 1992-1993 The Regents of the University of California.
// All rights reserved.  See copyright.h for copyright notice and limitation 
// of liability and disclaimer of warranty provisions.

#ifndef SYSTEM_H
#define SYSTEM_H

#include "copyright.h"
#include "utility.h"
#include "thread.h"
#include "scheduler.h"
#include "interrupt.h"
#include "stats.h"
#include "timer.h"
#include "synch.h"
#include <map>


// Initialization and cleanup routines
extern void Initialize(int argc, char **argv); 	// Initialization,
						// called before anything else
extern void Cleanup();				// Cleanup, called when
						// Nachos is done.

extern Thread *currentThread;			// the thread holding the CPU
extern Thread *threadToBeDestroyed;  		// the thread that just finished
extern Scheduler *scheduler;			// the ready list
extern Interrupt *interrupt;			// interrupt status
extern Statistics *stats;			// performance metrics
extern Timer *timer;				// the hardware alarm clock

#ifdef USER_PROGRAM
#include "machine.h"
#include "KernelLock.h"
#include "synch.h"
#include "Process.h"

extern Machine *machine;	// user program memory and registers
extern KernelLock **kernelLocks; //Array of Kernel Locks
extern int nextAvailableLock;
extern Lock *kernelLocksLock;
extern KernelCondition **kernelConds; //Array of Kernel Conditions
extern int nextAvailableCond;
extern Lock *kernelCondsLock;
#define NUM_KERNEL_LOCKS 400
#define NUM_KERNEL_CONDS 400
extern std::map<int,ProcessEntitity*> processTable;
extern int nextSpaceID;
extern Lock *processLock;
extern Lock *consoleLock; //To prevent threads from interrupting eachother with console usage
extern int pagesGivenOut;
extern Table* physicalMemoryTable;
extern Semaphore* MemorySemaphore;
#endif

#ifdef FILESYS_NEEDED 		// FILESYS or FILESYS_STUB 
#include "filesys.h"
#include "IPTEntry.h"
#include "bitmap.h"
#include <list>
#include "openfile.h"
extern FileSystem  *fileSystem;
extern int currentTlb;
extern IPTEntry *IPT;
extern OpenFile* swapFile;
extern std::list<int> fifoManager;
extern BitMap *swapMap;
extern bool USERAND;
#endif

#ifdef FILESYS
#include "synchdisk.h"
extern SynchDisk   *synchDisk;
#endif

#ifdef NETWORK
#include "post.h"
extern PostOffice* postOffice;
extern int machineID;
extern int nextMBID;
extern Lock* MBLock;
#endif


#endif // SYSTEM_H
